package com.cman777.springc.sample.config.ratelimit;


import com.cman777.springc.common.helper.IpUtils;
import com.cman777.springc.ratelimiter.collector.ServletCollector;
import com.cman777.springc.ratelimiter.collector.target.Target;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @author chenzhicong
 * @time 2020/9/18 16:53
 */
@Component("COMMON_COLLECTOR")
@Slf4j
public class ServeletCollector implements ServletCollector {
    @Override
    public Target collectTarget4Servlet(HttpServletRequest request) {
        CommonTarget target = new CommonTarget();
        target.setIp(IpUtils.getIpAddr(request));
        target.setUrl(request.getRequestURI());
        return target;
    }
}
